<?php

class clsAdminController
{
	public function get_All_Approved_UnApproved_Vehicles_For_Admin($isApproved)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;
		//$sql = "SELECT * FROM `tbl_car_basic` WHERE is_active='$isApproved' order by year DESC";
		$sql = "SELECT a.*, b.offered_price, b.featured_price FROM `tbl_car_basic` a, tbl_car_price b  WHERE a.unique_id=b.unique_id AND a.is_active='$isApproved' order by a.year DESC ";
		
		$run = mysql_query($sql);
		while($data=mysql_fetch_array($run))
		{
			$arrVehiclesHistory[$count]['id']=$data['id'];
			$arrVehiclesHistory[$count]['unique_id']=$data['unique_id'];
			$arrVehiclesHistory[$count]['year']=$data['year'];
			$arrVehiclesHistory[$count]['make']=$data['make'];
			$arrVehiclesHistory[$count]['model']=$data['model'];
			$arrVehiclesHistory[$count]['is_active']=$data['is_active'];
			$arrVehiclesHistory[$count]['stocknumber']=$data['stocknumber'];
			$arrVehiclesHistory[$count]['offered_price']=$data['offered_price'];
			$arrVehiclesHistory[$count]['featured_price']=$data['featured_price'];
			$arrVehiclesHistory[$count]['is_sold']=$data['is_sold'];
			$count++;
		}
		return $arrVehiclesHistory;
	}
	
	public function get_All_Approved_UnApproved_Vehicles_For_users($isApproved,$domain)
	{
		if($domain==0)
		{
			//$sql = "SELECT * FROM `tbl_car_basic` WHERE is_active='$isApproved' order by year DESC";
			$sql = "SELECT a.*, b.offered_price, b.featured_price FROM `tbl_car_basic` a, tbl_car_price b  WHERE a.unique_id=b.unique_id AND a.is_active='$isApproved' order by a.year DESC ";
		}
		else
		{
			$sql = "SELECT a.*, c.offered_price, c.featured_price FROM `tbl_domain_$domain` b, tbl_car_basic a, tbl_car_price c WHERE a.unique_id=c.unique_id AND a.is_active='$isApproved' AND a.unique_id=b.unique_id order by a.year DESC";
			//print $sql;
		}
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;	
		$run = mysql_query($sql);
		while($data=mysql_fetch_array($run))
		{
			$arrVehiclesHistory[$count]['id']=$data['id'];
			$arrVehiclesHistory[$count]['unique_id']=$data['unique_id'];
			$arrVehiclesHistory[$count]['year']=$data['year'];
			$arrVehiclesHistory[$count]['make']=$data['make'];
			$arrVehiclesHistory[$count]['model']=$data['model'];
			$arrVehiclesHistory[$count]['is_active']=$data['is_active'];
			$arrVehiclesHistory[$count]['stocknumber']=$data['stocknumber'];
			$arrVehiclesHistory[$count]['offered_price']=$data['offered_price'];
			$arrVehiclesHistory[$count]['featured_price']=$data['featured_price'];
			$arrVehiclesHistory[$count]['is_sold']=$data['is_sold'];
			$count++;
		}
		return $arrVehiclesHistory;
	}
	
	public function get_All_New_Used_Vehicles_For_Admin($car_status)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;
		$sql = "SELECT a.*,b.offered_price, b.featured_price  FROM `tbl_car_basic` a, `tbl_car_price` b WHERE a.unique_id=b.unique_id AND a.car_status='$car_status' order by a.year DESC";
		//print "--->>".$sql;
		$run = mysql_query($sql);
		while($data=mysql_fetch_array($run))
		{			
			$arrVehiclesHistory[$count]['id']=$data['id'];
			$arrVehiclesHistory[$count]['unique_id']=$data['unique_id'];
			$arrVehiclesHistory[$count]['year']=$data['year'];
			$arrVehiclesHistory[$count]['make']=$data['make'];
			$arrVehiclesHistory[$count]['model']=$data['model'];
			$arrVehiclesHistory[$count]['is_active']=$data['is_active'];
			$arrVehiclesHistory[$count]['stocknumber']=$data['stocknumber'];
			$arrVehiclesHistory[$count]['offered_price']=$data['offered_price'];
			$arrVehiclesHistory[$count]['featured_price']=$data['featured_price'];
			$arrVehiclesHistory[$count]['is_sold']=$data['is_sold'];
			$count++;
		}
		return $arrVehiclesHistory;
	}
	
	public function get_All_New_Used_Vehicles_For_Users($car_status,$domain)
	{
		if($domain==0)
		{
			$sql = "SELECT a.*, b.offered_price,b.featured_price FROM `tbl_car_basic` a, `tbl_car_price` b  WHERE  a.unique_id=b.unique_id AND a.car_status='$car_status' order by a.year DESC";
		}
		else
		{
			$sql = "SELECT a.*,c.offered_price,c.featured_price FROM `tbl_domain_$domain` b, tbl_car_basic a, `tbl_car_price` c WHERE a.unique_id=c.unique_id AND a.car_status='$car_status' AND a.unique_id=b.unique_id order by a.year DESC";
			//print $sql;
		}
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;
		
		$run = mysql_query($sql);
		while($data=mysql_fetch_array($run))
		{
			$arrVehiclesHistory[$count]['id']=$data['id'];
			$arrVehiclesHistory[$count]['unique_id']=$data['unique_id'];
			$arrVehiclesHistory[$count]['year']=$data['year'];
			$arrVehiclesHistory[$count]['make']=$data['make'];
			$arrVehiclesHistory[$count]['model']=$data['model'];
			$arrVehiclesHistory[$count]['is_active']=$data['is_active'];
			$arrVehiclesHistory[$count]['stocknumber']=$data['stocknumber'];
			$arrVehiclesHistory[$count]['offered_price']=$data['offered_price'];
			$arrVehiclesHistory[$count]['featured_price']=$data['featured_price'];
			$arrVehiclesHistory[$count]['is_sold']=$data['is_sold'];
			$count++;
		}
		return $arrVehiclesHistory;
	}
	
	
	public function getUserData($username)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;
		$sql = "SELECT * FROM `tbl_admin_users` WHERE user_name='$username' ";
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$arrVehiclesHistory['userid']=$data['id'];
			$arrVehiclesHistory['username']=$data['user_name'];
			$arrVehiclesHistory['domain']=$data['domain'];
			$arrVehiclesHistory['is_super_admin']=$data['is_super_admin'];
			$arrVehiclesHistory['is_admin']=$data['is_admin'];
		}
		return $arrVehiclesHistory;	
	}
	
	public function get_All_Featured_Vehicles_For_Admin($domain)
	{
		if($domain==0)
		{
			$sql = "SELECT a.* FROM `tbl_car_basic` a, tbl_car_featured b WHERE a.unique_id=b.unique_id AND b.is_featured='y' order by year DESC";
		}
		else
		{
			$sql = "SELECT a.* FROM `tbl_car_basic` a, tbl_domain_$domain b WHERE a.unique_id=b.unique_id AND b.is_featured='y' order by year DESC";
		}
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;
		
		$run = mysql_query($sql);
		while($data=mysql_fetch_array($run))
		{
			$arrVehiclesHistory[$count]['id']=$data['id'];
			$arrVehiclesHistory[$count]['unique_id']=$data['unique_id'];
			$arrVehiclesHistory[$count]['year']=$data['year'];
			$arrVehiclesHistory[$count]['make']=$data['make'];
			$arrVehiclesHistory[$count]['model']=$data['model'];
			$arrVehiclesHistory[$count]['is_active']=$data['is_active'];
			$arrVehiclesHistory[$count]['stocknumber']=$data['stocknumber'];
			$arrVehiclesHistory[$count]['is_sold']=$data['is_sold'];
			$count++;
		}
		return $arrVehiclesHistory;
	}
	
	function LoginProcessDomain($username,$password,$ddlDomain)
	{
		
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$sql = "SELECT COUNT(*) as cntAdmin FROM tbl_admin_users WHERE user_name='".$username."' AND password='".$password."' AND domain='".$ddlDomain."' AND is_active='Y' ";
		//print $sql;exit;
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$cntAdmin = $data['cntAdmin'];
		}
		return $cntAdmin;
	}
	
}